```{r include=FALSE}
ipak <- function(pkg){
  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  if (length(new.pkg))
    install.packages(new.pkg, dependencies = TRUE, repos = "http://cran.us.r-project.org")
  sapply(pkg, require, character.only = TRUE)
}

packages <- c("psych", "foreign","readstata13", "multcomp", "summarytools", "quantreg", "ggbeeswarm",
              "ggplot2","stargazer","jtools", "tidyverse", "BayesFactor", "gridExtra", "ggpubr", "nnet", "naniar")

ipak(packages)

##LOAD DATA 
cces12 <- read.dta13("CCES12_SNH_anchor.DTA")
qualtrics15 <- read.dta13("Qualtrics 2015.dta")
cces18 <- read.dta13("CCES18_UCM_unmatched_OUTPUT.dta")

#####################################CCES12 Recodes#####################################

#Demographics
cces12$age<-2012-cces12$birthyr
cces12$white<-0
cces12$white[cces12$race=="White"]<-1
cces12$female<-0
cces12$female[cces12$gender=="Female"]<-1
cces12$conservative<-as.numeric(cces12$CC334A)
cces12$conservative[as.numeric(cces12$CC334A)==8]<-NA
cces12$partyid<-as.numeric(cces12$pid7)
cces12$partyid[as.numeric(cces12$pid7)==8]<-NA
cces12$income<-as.numeric(cces12$faminc)
cces12$incmiss<-0
cces12$incmiss[cces12$income>16]<-1
cces12$income_wmissing<-cces12$income
cces12$income_wmissing[cces12$income>16]<-NA
cces12$education<-as.numeric(cces12$educ)

cces12$Democrat<-NA
cces12$Democrat[cces12$partyid==1]<-1
cces12$Democrat[cces12$partyid==2]<-1
cces12$Democrat[cces12$partyid==3]<-1
cces12$Democrat[cces12$partyid==5]<-0
cces12$Democrat[cces12$partyid==6]<-0
cces12$Democrat[cces12$partyid==7]<-0


#Irrelevant Anchor
cces12$anchor65<-recode(cces12$SNI301_treat, "1"=0, "2"=1)

#Relevant Anchors
#Cigarette Tax
cces12$cigtreat<-as.numeric(cces12$SNI309_treat)

cces12$CigTaxLow<-0
cces12$CigTaxLow[cces12$cigtreat==1]<-1
cces12$CigTaxLow[cces12$cigtreat==2]<-1
cces12$CigTaxLow[cces12$cigtreat==3]<-1

cces12$CigTaxHigh<-0
cces12$CigTaxHigh[cces12$cigtreat==4]<-1
cces12$CigTaxHigh[cces12$cigtreat==5]<-1
cces12$CigTaxHigh[cces12$cigtreat==6]<-1

cces12$pid7n<-as.numeric(cces12$pid7)
cces12$pid3lean<-NA
cces12$pid3lean[cces12$pid7n<4]<--1
cces12$pid3lean[cces12$pid7n==4]<-0
cces12$pid3lean[cces12$pid7n>4 & cces12$pid7n<8]<-1

##Party Cue Treatments
#1=low, no cue; 2=high, no cue
#3=low, in cue, 4=high, in cue
#5=low, out cue, 6=high, out cue
cces12$CTtreatment<-NA
cces12$CTtreatment[cces12$cigtreat==1 & cces12$pid3lean!=0]<-1
cces12$CTtreatment[cces12$cigtreat==4 & cces12$pid3lean!=0]<-2
cces12$CTtreatment[cces12$cigtreat==3 & cces12$pid3lean==-1]<-3
cces12$CTtreatment[cces12$cigtreat==2 & cces12$pid3lean==1]<-3
cces12$CTtreatment[cces12$cigtreat==5 & cces12$pid3lean==-1]<-4
cces12$CTtreatment[cces12$cigtreat==6 & cces12$pid3lean==1]<-4
cces12$CTtreatment[cces12$cigtreat==3 & cces12$pid3lean==1]<-5
cces12$CTtreatment[cces12$cigtreat==2 & cces12$pid3lean==-1]<-5
cces12$CTtreatment[cces12$cigtreat==5 & cces12$pid3lean==1]<-6
cces12$CTtreatment[cces12$cigtreat==6 & cces12$pid3lean==-1]<-6

#1=no cue, 2=in cue, 3=out cue
cces12$CTpartytreat<-NA
cces12$CTpartytreat[cces12$cigtreat==1 & cces12$pid3lean!=0]<-1
cces12$CTpartytreat[cces12$cigtreat==4 & cces12$pid3lean!=0]<-1
cces12$CTpartytreat[cces12$cigtreat==3 & cces12$pid3lean==-1]<-2
cces12$CTpartytreat[cces12$cigtreat==2 & cces12$pid3lean==1]<-2
cces12$CTpartytreat[cces12$cigtreat==5 & cces12$pid3lean==-1]<-2
cces12$CTpartytreat[cces12$cigtreat==6 & cces12$pid3lean==1]<-2
cces12$CTpartytreat[cces12$cigtreat==3 & cces12$pid3lean==1]<-3
cces12$CTpartytreat[cces12$cigtreat==2 & cces12$pid3lean==-1]<-3
cces12$CTpartytreat[cces12$cigtreat==5 & cces12$pid3lean==1]<-3
cces12$CTpartytreat[cces12$cigtreat==6 & cces12$pid3lean==-1]<-3

#Cigarette Tax Preference
cces12$cdollars<-as.numeric(cces12$SNI309_dollars)-1
cces12$ccents<-(as.numeric(cces12$SNI309_cents)-1)/100

cces12$CigTaxPref<-cces12$cdollars+cces12$ccents

#Gas Tax
cces12$gastreat<-as.numeric(cces12$SNI414_treat)

cces12$gasTaxLow<-0
cces12$gasTaxLow[cces12$gastreat==1]<-1
cces12$gasTaxLow[cces12$gastreat==2]<-1
cces12$gasTaxLow[cces12$gastreat==3]<-1

cces12$gasTaxHigh<-0
cces12$gasTaxHigh[cces12$gastreat==4]<-1
cces12$gasTaxHigh[cces12$gastreat==5]<-1
cces12$gasTaxHigh[cces12$gastreat==6]<-1

#1=low, no cue; 2=high, no cue
#3=low, in cue, 4=high, in cue
#5=low, out cue, 6=high, out cue
cces12$GTtreatment<-NA
cces12$GTtreatment[cces12$gastreat==1 & cces12$pid3lean!=0]<-1
cces12$GTtreatment[cces12$gastreat==4 & cces12$pid3lean!=0]<-2
cces12$GTtreatment[cces12$gastreat==3 & cces12$pid3lean==-1]<-3
cces12$GTtreatment[cces12$gastreat==2 & cces12$pid3lean==1]<-3
cces12$GTtreatment[cces12$gastreat==5 & cces12$pid3lean==-1]<-4
cces12$GTtreatment[cces12$gastreat==6 & cces12$pid3lean==1]<-4
cces12$GTtreatment[cces12$gastreat==3 & cces12$pid3lean==1]<-5
cces12$GTtreatment[cces12$gastreat==2 & cces12$pid3lean==-1]<-5
cces12$GTtreatment[cces12$gastreat==5 & cces12$pid3lean==1]<-6
cces12$GTtreatment[cces12$gastreat==6 & cces12$pid3lean==-1]<-6

#1=no cue, 2=in cue, 3=out cue
cces12$GTpartytreat<-NA
cces12$GTpartytreat[cces12$gastreat==1 & cces12$pid3lean!=0]<-1
cces12$GTpartytreat[cces12$gastreat==4 & cces12$pid3lean!=0]<-1
cces12$GTpartytreat[cces12$gastreat==3 & cces12$pid3lean==-1]<-2
cces12$GTpartytreat[cces12$gastreat==2 & cces12$pid3lean==1]<-2
cces12$GTpartytreat[cces12$gastreat==5 & cces12$pid3lean==-1]<-2
cces12$GTpartytreat[cces12$gastreat==6 & cces12$pid3lean==1]<-2
cces12$GTpartytreat[cces12$gastreat==3 & cces12$pid3lean==1]<-3
cces12$GTpartytreat[cces12$gastreat==2 & cces12$pid3lean==-1]<-3
cces12$GTpartytreat[cces12$gastreat==5 & cces12$pid3lean==1]<-3
cces12$GTpartytreat[cces12$gastreat==6 & cces12$pid3lean==-1]<-3

#Gas Tax Preference
cces12$gdollars<-as.numeric(cces12$SNI414_dollars)-1
cces12$gcents<-(as.numeric(cces12$SNI414_cents)-1)/100

cces12$GasTaxPref<-cces12$gdollars+cces12$gcents


#####################Qualtrics 2015 Recodes#####################################

#Demographics
qualtrics15$age<-2014-(1900+qualtrics15$dob)
qualtrics15$female<-0
qualtrics15$female[qualtrics15$sex==2]<-1
qualtrics15$pid7<-NA
qualtrics15$pid7[qualtrics15$strdem==1]<-1
qualtrics15$pid7[qualtrics15$strdem==2]<-2
qualtrics15$pid7[qualtrics15$lean==2]<-3
qualtrics15$pid7[qualtrics15$lean==3]<-4
qualtrics15$pid7[qualtrics15$lean==1]<-5
qualtrics15$pid7[qualtrics15$strrep==2]<-6
qualtrics15$pid7[qualtrics15$strrep==1]<-7
qualtrics15$white<-0
qualtrics15$white[qualtrics15$race==2]<-1
qualtrics15$white[is.na(qualtrics15$race)==TRUE]<-NA


#Irrelevant Anchor

qualtrics15$IrrelTreat<-as.numeric(as.factor(qualtrics15$tax))

qualtrics15$anchor65<-NA
qualtrics15$anchor65[qualtrics15$number==10]<-0
qualtrics15$anchor65[qualtrics15$number==65]<-1

##Relevant Anchors

qualtrics15$PrisonHigh<-as.numeric(as.factor(qualtrics15$prisno))
qualtrics15$PrisonHigh[qualtrics15$PrisonHigh==2]<-0
qualtrics15$PrisonHigh[qualtrics15$PrisonHigh==1]<-1

qualtrics15$SenateHigh<-NA
qualtrics15$SenateHigh[qualtrics15$senateno==6]<-0
qualtrics15$SenateHigh[qualtrics15$senateno==16]<-1

qualtrics15$unemptreat<-as.numeric(as.factor(qualtrics15$unempno))

qualtrics15$UnempWeeksHigh<-NA
qualtrics15$UnempWeeksHigh[qualtrics15$unemptreat==1]<-0
qualtrics15$UnempWeeksHigh[qualtrics15$unemptreat==3]<-1

qualtrics15$UnempMonthsHigh<-NA
qualtrics15$UnempMonthsHigh[qualtrics15$unemptreat==2]<-0
qualtrics15$UnempMonthsHigh[qualtrics15$unemptreat==4]<-1

qualtrics15$immigtreat<-as.numeric(as.factor(qualtrics15$immigno))

qualtrics15$ImmigMonthsHigh<-NA
qualtrics15$ImmigMonthsHigh[qualtrics15$immigtreat==2]<-0
qualtrics15$ImmigMonthsHigh[qualtrics15$immigtreat==4]<-1

qualtrics15$ImmigYearsHigh<-NA
qualtrics15$ImmigYearsHigh[qualtrics15$immigtreat==1]<-0
qualtrics15$ImmigYearsHigh[qualtrics15$immigtreat==3]<-1


#####################CCES 2018 Recodes#####################################

#Demographics
cces18$age<-2012-cces18$birthyr
cces18$white<-0
cces18$white[cces18$race==1]<-1
cces18$female<-0
cces18$female[cces18$gender==2]<-1
cces18$conservative<-cces18$ideo5
cces18$conservative[cces18$ideo5>5]<-NA
cces18$partyid<-cces18$pid7
cces18$partyid[cces18$pid7==8]<-NA
cces18$income<-cces18$faminc_new
cces18$incmiss<-0
cces18$incmiss[cces18$faminc_new>16]<-1
cces18$income_wmissing<-cces18$faminc_new
cces18$income_wmissing[cces18$faminc_new>16]<-NA
cces18$education<-cces18$educ

cces18$Democrat<-NA
cces18$Democrat[cces18$partyid==1]<-1
cces18$Democrat[cces18$partyid==2]<-1
cces18$Democrat[cces18$partyid==3]<-1
cces18$Democrat[cces18$partyid==5]<-0
cces18$Democrat[cces18$partyid==6]<-0
cces18$Democrat[cces18$partyid==7]<-0

#Irrelevant Anchors
cces18$IAnum<-cces18$UCMAnchor_number*5
cces18$IAnum[cces18$UCMAnchor==2]<-0

cces18$murder<-cces18$UCM3A
cces18$maxterm<-cces18$UCM3B
cces18$maxunemp<-cces18$UCM3C
cces18$legalimmigwait<-cces18$UCM3D
cces18$undocimmigwait<-cces18$UCM3E

cces18$murder[cces18$UCM3A==-8]<-NA
cces18$murder[cces18$UCM3A==-9]<-NA
cces18$maxterm[cces18$UCM3B==-8]<-NA
cces18$maxterm[cces18$UCM3B==-9]<-NA
cces18$maxunemp[cces18$UCM3C==-8]<-NA
cces18$maxunemp[cces18$UCM3C==-9]<-NA
cces18$legalimmigwait[cces18$UCM3D==-8]<-NA
cces18$legalimmigwait[cces18$UCM3D==-9]<-NA
cces18$undocimmigwait[cces18$UCM3E==-8]<-NA
cces18$undocimmigwait[cces18$UCM3E==-9]<-NA


####Relecant Anchors

##Gas Tax Replication Treatment
#Collapsed
#0=low, 1=high
cces18$GTtreatment01<-NA
cces18$GTtreatment01[cces18$UCMGasAnchor==1]<-0
cces18$GTtreatment01[cces18$UCMGasAnchor==4]<-1
cces18$GTtreatment01[cces18$UCMGasAnchor==2]<-0
cces18$GTtreatment01[cces18$UCMGasAnchor==3]<-0
cces18$GTtreatment01[cces18$UCMGasAnchor==6]<-1
cces18$GTtreatment01[cces18$UCMGasAnchor==5]<-1

#1=low, no cue; 2=high, no cue
#3=low, in cue, 4=high, in cue
#5=low, out cue, 6=high, out cue
cces18$GTtreatment<-NA
cces18$GTtreatment[cces18$UCMGasAnchor==1 & cces18$pid3lean!=0]<-1
cces18$GTtreatment[cces18$UCMGasAnchor==4 & cces18$pid3lean!=0]<-2
cces18$GTtreatment[cces18$UCMGasAnchor==2 & cces18$pid3lean==1]<-3
cces18$GTtreatment[cces18$UCMGasAnchor==3 & cces18$pid3lean==-1]<-3
cces18$GTtreatment[cces18$UCMGasAnchor==6 & cces18$pid3lean==1]<-4
cces18$GTtreatment[cces18$UCMGasAnchor==5 & cces18$pid3lean==-1]<-4
cces18$GTtreatment[cces18$UCMGasAnchor==2 & cces18$pid3lean==-1]<-5
cces18$GTtreatment[cces18$UCMGasAnchor==3 & cces18$pid3lean==1]<-5
cces18$GTtreatment[cces18$UCMGasAnchor==6 & cces18$pid3lean==-1]<-6
cces18$GTtreatment[cces18$UCMGasAnchor==5 & cces18$pid3lean==1]<-6

#1=no cue, 2=in cute, 3=out cue
cces18$GTpartytreat<-NA
cces18$GTpartytreat[cces18$UCMGasAnchor==1 & cces18$pid3lean!=0]<-1
cces18$GTpartytreat[cces18$UCMGasAnchor==4 & cces18$pid3lean!=0]<-1
cces18$GTpartytreat[cces18$UCMGasAnchor==2 & cces18$pid3lean==1]<-2
cces18$GTpartytreat[cces18$UCMGasAnchor==3 & cces18$pid3lean==-1]<-2
cces18$GTpartytreat[cces18$UCMGasAnchor==6 & cces18$pid3lean==1]<-2
cces18$GTpartytreat[cces18$UCMGasAnchor==5 & cces18$pid3lean==-1]<-2
cces18$GTpartytreat[cces18$UCMGasAnchor==2 & cces18$pid3lean==-1]<-3
cces18$GTpartytreat[cces18$UCMGasAnchor==3 & cces18$pid3lean==1]<-3
cces18$GTpartytreat[cces18$UCMGasAnchor==6 & cces18$pid3lean==-1]<-3
cces18$GTpartytreat[cces18$UCMGasAnchor==5 & cces18$pid3lean==1]<-3
cces18$GTpartytreat<-factor(cces18$GTpartytreat)

#Gas Tax Preference
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM8A_int = c(-9,-8)))
cces18$UCM8A_int<-data2$UCM8A_int
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM8B_int = c(-9,-8)))
cces18$UCM8B_int<-data2$UCM8B_int
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM8C_int = c(-9,-8)))
cces18$UCM8C_int<-data2$UCM8C_int
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM8D_int = c(-9,-8)))
cces18$UCM8D_int<-data2$UCM8D_int
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM8E_int = c(-9,-8)))
cces18$UCM8E_int<-data2$UCM8E_int
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM8F_int = c(-9,-8)))
cces18$UCM8F_int<-data2$UCM8F_int

cces18$GasTaxPref<-coalesce(cces18$UCM8A_int, cces18$UCM8B_int, cces18$UCM8C_int, cces18$UCM8D_int, cces18$UCM8E_int, cces18$UCM8F_int)


##Gun Wait Treatment
#Collapsed
#0=low, 1=high
cces18$GWtreatment01<-NA
cces18$GWtreatment01[cces18$UCM12==1]<-0
cces18$GWtreatment01[cces18$UCM12==2]<-1
cces18$GWtreatment01[cces18$UCM12==3]<-0
cces18$GWtreatment01[cces18$UCM12==4]<-0
cces18$GWtreatment01[cces18$UCM12==5]<-1
cces18$GWtreatment01[cces18$UCM12==6]<-1

#1=low, no cue; 2=high, no cue
#3=low, in cue, 4=high, in cue
#5=low, out cue, 6=high, out cue
cces18$GWtreatment<-NA
cces18$GWtreatment[cces18$UCM12==1 & cces18$pid3lean!=0]<-1
cces18$GWtreatment[cces18$UCM12==2 & cces18$pid3lean!=0]<-2
cces18$GWtreatment[cces18$UCM12==3 & cces18$pid3lean==-1]<-3
cces18$GWtreatment[cces18$UCM12==4 & cces18$pid3lean==1]<-3
cces18$GWtreatment[cces18$UCM12==5 & cces18$pid3lean==-1]<-4
cces18$GWtreatment[cces18$UCM12==6 & cces18$pid3lean==1]<-4
cces18$GWtreatment[cces18$UCM12==3 & cces18$pid3lean==1]<-5
cces18$GWtreatment[cces18$UCM12==4 & cces18$pid3lean==-1]<-5
cces18$GWtreatment[cces18$UCM12==5 & cces18$pid3lean==1]<-6
cces18$GWtreatment[cces18$UCM12==6 & cces18$pid3lean==-1]<-6

#1=no cue, 2=in cute, 3=out cue
cces18$GWpartytreat<-NA
cces18$GWpartytreat[cces18$UCM12==1 & cces18$pid3lean!=0]<-1
cces18$GWpartytreat[cces18$UCM12==2 & cces18$pid3lean!=0]<-1
cces18$GWpartytreat[cces18$UCM12==3 & cces18$pid3lean==-1]<-2
cces18$GWpartytreat[cces18$UCM12==4 & cces18$pid3lean==1]<-2
cces18$GWpartytreat[cces18$UCM12==5 & cces18$pid3lean==-1]<-2
cces18$GWpartytreat[cces18$UCM12==6 & cces18$pid3lean==1]<-2
cces18$GWpartytreat[cces18$UCM12==3 & cces18$pid3lean==1]<-3
cces18$GWpartytreat[cces18$UCM12==4 & cces18$pid3lean==-1]<-3
cces18$GWpartytreat[cces18$UCM12==5 & cces18$pid3lean==1]<-3
cces18$GWpartytreat[cces18$UCM12==6 & cces18$pid3lean==-1]<-3

#Gun Wait Pference
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM12A = c(-9,-8)))
cces18$UCM12A<-data2$UCM12A
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM12B = c(-9,-8)))
cces18$UCM12B<-data2$UCM12B
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM12C = c(-9,-8)))
cces18$UCM12C<-data2$UCM12C
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM12D = c(-9,-8)))
cces18$UCM12D<-data2$UCM12D
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM12E = c(-9,-8)))
cces18$UCM12E<-data2$UCM12E
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM12F = c(-9,-8)))
cces18$UCM12F<-data2$UCM12F

cces18$GunWaitPref<-coalesce(cces18$UCM12A, cces18$UCM12B, cces18$UCM12C, cces18$UCM12D, cces18$UCM12E, cces18$UCM12F)



##Border Tax Treatment
#Collapsed
#0=low, 1=high
cces18$BTtreatment01<-NA
cces18$BTtreatment01[cces18$UCM38==1]<-0
cces18$BTtreatment01[cces18$UCM38==2]<-1
cces18$BTtreatment01[cces18$UCM38==3]<-0
cces18$BTtreatment01[cces18$UCM38==4]<-0
cces18$BTtreatment01[cces18$UCM38==5]<-1
cces18$BTtreatment01[cces18$UCM38==6]<-1

#1=low, no cue; 2=high, no cue
#3=low, in cue, 4=high, in cue
#5=low, out cue, 6=high, out cue
cces18$BTtreatment<-NA
cces18$BTtreatment[cces18$UCM38==1 & cces18$pid3lean!=0]<-1
cces18$BTtreatment[cces18$UCM38==2 & cces18$pid3lean!=0]<-2
cces18$BTtreatment[cces18$UCM38==3 & cces18$pid3lean==-1]<-3
cces18$BTtreatment[cces18$UCM38==4 & cces18$pid3lean==1]<-3
cces18$BTtreatment[cces18$UCM38==5 & cces18$pid3lean==-1]<-4
cces18$BTtreatment[cces18$UCM38==6 & cces18$pid3lean==1]<-4
cces18$BTtreatment[cces18$UCM38==3 & cces18$pid3lean==1]<-5
cces18$BTtreatment[cces18$UCM38==4 & cces18$pid3lean==-1]<-5
cces18$BTtreatment[cces18$UCM38==5 & cces18$pid3lean==1]<-6
cces18$BTtreatment[cces18$UCM38==6 & cces18$pid3lean==-1]<-6

#1=no cue, 2=in cute, 3=out cue
cces18$BTpartytreat<-NA
cces18$BTpartytreat[cces18$UCM38==1 & cces18$pid3lean!=0]<-1
cces18$BTpartytreat[cces18$UCM38==2 & cces18$pid3lean!=0]<-1
cces18$BTpartytreat[cces18$UCM38==3 & cces18$pid3lean==-1]<-2
cces18$BTpartytreat[cces18$UCM38==4 & cces18$pid3lean==1]<-2
cces18$BTpartytreat[cces18$UCM38==5 & cces18$pid3lean==-1]<-2
cces18$BTpartytreat[cces18$UCM38==6 & cces18$pid3lean==1]<-2
cces18$BTpartytreat[cces18$UCM38==3 & cces18$pid3lean==1]<-3
cces18$BTpartytreat[cces18$UCM38==4 & cces18$pid3lean==-1]<-3
cces18$BTpartytreat[cces18$UCM38==5 & cces18$pid3lean==1]<-3
cces18$BTpartytreat[cces18$UCM38==6 & cces18$pid3lean==-1]<-3

#Border Tax Pference
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM38A = "__NA__"))
cces18$UCM38A<-as.numeric(data2$UCM38A)
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM38B = "__NA__"))
cces18$UCM38B<-as.numeric(data2$UCM38B)
cces18$UCM38C[cces18$UCM38C=="1p"]<-"1"
cces18$UCM38C[cces18$UCM38C=="5%"]<-"5"
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM38C = "__NA__"))
cces18$UCM38C<-as.numeric(data2$UCM38C)
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM38D = "__NA__"))
cces18$UCM38D<-as.numeric(data2$UCM38D)
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM38E = c("__NA__","?")))
cces18$UCM38E<-as.numeric(data2$UCM38E)
cces18$UCM38F[cces18$UCM38F=="35%"]<-"35"
cces18$UCM38F[cces18$UCM38F=="40%"]<-"40"
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM38F = "__NA__"))
cces18$UCM38F<-as.numeric(data2$UCM38F)

cces18$BorderTaxPref<-coalesce(cces18$UCM38A, cces18$UCM38B, cces18$UCM38C, cces18$UCM38D, cces18$UCM38E, cces18$UCM38F)


##Animal Testing Treatment
#Collapsed
#0=low, 1=high
cces18$ATtreatment01<-NA
cces18$ATtreatment01[cces18$UCM30==1]<-0
cces18$ATtreatment01[cces18$UCM30==2]<-1
cces18$ATtreatment01[cces18$UCM30==3]<-0
cces18$ATtreatment01[cces18$UCM30==4]<-0
cces18$ATtreatment01[cces18$UCM30==5]<-1
cces18$ATtreatment01[cces18$UCM30==6]<-1

#1=low, no cue; 2=high, no cue
#3=low, in cue, 4=high, in cue
#5=low, out cue, 6=high, out cue
cces18$ATtreatment<-NA
cces18$ATtreatment[cces18$UCM30==1 & cces18$pid3lean!=0]<-1
cces18$ATtreatment[cces18$UCM30==2 & cces18$pid3lean!=0]<-2
cces18$ATtreatment[cces18$UCM30==3 & cces18$pid3lean==-1]<-3
cces18$ATtreatment[cces18$UCM30==4 & cces18$pid3lean==1]<-3
cces18$ATtreatment[cces18$UCM30==5 & cces18$pid3lean==-1]<-4
cces18$ATtreatment[cces18$UCM30==6 & cces18$pid3lean==1]<-4
cces18$ATtreatment[cces18$UCM30==3 & cces18$pid3lean==1]<-5
cces18$ATtreatment[cces18$UCM30==4 & cces18$pid3lean==-1]<-5
cces18$ATtreatment[cces18$UCM30==5 & cces18$pid3lean==1]<-6
cces18$ATtreatment[cces18$UCM30==6 & cces18$pid3lean==-1]<-6

#1=no cue, 2=in cute, 3=out cue
cces18$ATpartytreat<-NA
cces18$ATpartytreat[cces18$UCM30==1 & cces18$pid3lean!=0]<-1
cces18$ATpartytreat[cces18$UCM30==2 & cces18$pid3lean!=0]<-1
cces18$ATpartytreat[cces18$UCM30==3 & cces18$pid3lean==-1]<-2
cces18$ATpartytreat[cces18$UCM30==4 & cces18$pid3lean==1]<-2
cces18$ATpartytreat[cces18$UCM30==5 & cces18$pid3lean==-1]<-2
cces18$ATpartytreat[cces18$UCM30==6 & cces18$pid3lean==1]<-2
cces18$ATpartytreat[cces18$UCM30==3 & cces18$pid3lean==1]<-3
cces18$ATpartytreat[cces18$UCM30==4 & cces18$pid3lean==-1]<-3
cces18$ATpartytreat[cces18$UCM30==5 & cces18$pid3lean==1]<-3
cces18$ATpartytreat[cces18$UCM30==6 & cces18$pid3lean==-1]<-3

#Animal Testing Preference
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM30A = c(-9,-8)))
cces18$UCM30A<-data2$UCM30A
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM30B = c(-9,-8)))
cces18$UCM30B<-data2$UCM30B
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM30C = c(-9,-8)))
cces18$UCM30C<-data2$UCM30C
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM30D = c(-9,-8)))
cces18$UCM30D<-data2$UCM30D
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM30E = c(-9,-8)))
cces18$UCM30E<-data2$UCM30E
data2 <-cces18 %>% naniar::replace_with_na(replace = list(UCM30F = c(-9,-8)))
cces18$UCM30F<-data2$UCM30F

cces18$AnimalTestingPref<-coalesce(cces18$UCM30A, cces18$UCM30B, cces18$UCM30C, cces18$UCM30D, cces18$UCM30E, cces18$UCM30F)


```